package com.chen.controller;

import com.chen.common.Result;
import com.chen.pojo.User;
import com.chen.service.Impl.LoginServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@Api(value = "LoginController", tags = "账户操作")
@SuppressWarnings("all")
@Slf4j
@RequestMapping("/user")
public class LoginController {

    @Resource
    private LoginServiceImpl loginService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public Result login(@RequestBody User user) {
        return loginService.login(user);
    }

    @GetMapping(value = "/info")
    public Result info() {

        HashMap<String, Object> responseData = new HashMap<>();
        responseData.put("roles", "admin");
        responseData.put("name", "Super admin");
        responseData.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        return Result.success(responseData);
    }

    @PostMapping("/logout")
    @ApiOperation("退出")
    public Result logout() {
        HashMap<String, Object> responseData = new HashMap<>();
        responseData.remove(responseData);
        return Result.success(responseData);
    }

    //注册
    @ApiOperation("注册")
    @PostMapping("/register")
    public Result register(@RequestBody User user){
       return loginService.register(user);
    }

    @PutMapping("/forget")
    @ApiOperation("忘记密码")
    public Result forget(@RequestBody User user){
        return Result.success(loginService.forget(user));
    }

    @PutMapping("/reset")
    @ApiOperation("重置密码")
    public Result reset(@RequestBody User user){
        return Result.success(loginService.reset(user));
    }
}
